﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApMultipleLocationsManipulationEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApMultipleLocationsManipulationEnabler : ITxCommandEnabler
{
  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    bool flag1 = false;
    if (!TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded())
      flag1 = false;
    bool flag2;
    if (this.GetSelectesItemsCount() == 0)
    {
      flag2 = true;
    }
    else
    {
      TxObjectList andOperationsList = this.GetSelectedLocationsAndOperationsList();
      flag2 = ((Collection<ITxObject>) this.GetSelectedLocations(andOperationsList)).Count != 0 || ((Collection<ITxObject>) this.GetSelectedOperations(andOperationsList)).Count != 0;
    }
    return flag2;
  }

  private int GetSelectesItemsCount() => TxApplication.ActiveSelection.Count;

  internal TxObjectList GetSelectedLocations(TxObjectList theList)
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter(typeof (ITxLocationOperation));
    if (TxApplication.PlatformMode == 2)
      txTypeFilter.AddExcludedType(typeof (TxWeldLocationOperation));
    return txTypeFilter.Filter(theList);
  }

  private TxObjectList GetSelectedOperations(TxObjectList theList)
  {
    return new TxTypeFilter(typeof (ITxOrderedCompoundOperation)).Filter(theList);
  }

  internal TxObjectList GetSelectedLocationsAndOperationsList()
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    txTypeFilter.AddIncludedType(typeof (ITxLocationOperation));
    txTypeFilter.AddIncludedType(typeof (ITxOrderedCompoundOperation));
    return TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
  }
}
